﻿using HML.Design;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;

namespace HML
{
    /// <summary>
    /// SingleAccordion节点
    /// </summary>
    [TypeConverter(typeof(PropertyOrderConverter))]
    public abstract class SingleAccordionNode
    {
        #region 属性

        private SingleAccordionMouseAnimationEnableds mouseAnimationEnabled = SingleAccordionMouseAnimationEnableds.Auto;
        /// <summary>
        /// 是否启用节点鼠标动画（Auto采用通用设置）
        /// </summary>
        [Description("是否启用节点鼠标动画（Auto采用通用设置）")]
        [Category("杂项")]
        [PropertyOrder(-190)]
        [DefaultValue(SingleAccordionMouseAnimationEnableds.Auto)]
        public SingleAccordionMouseAnimationEnableds MouseAnimationEnabled
        {
            get { return this.mouseAnimationEnabled; }
            set
            {
                if (this.mouseAnimationEnabled == value)
                    return;

                this.mouseAnimationEnabled = value;
                if (this.Owner != null)
                {
                    this.Owner.RemoveNodeMouseAnimation();
                }
            }
        }

        private int lRAnimationDistance = -1;
        /// <summary>
        /// 左右滑动动画距离（-1采用通用设置）
        /// </summary>
        [Description("左右滑动动画距离（-1采用通用设置）")]
        [Category("杂项")]
        [PropertyOrder(-188)]
        [DefaultValue(-1)]
        public int LRAnimationDistance
        {
            get { return this.lRAnimationDistance; }
            set
            {
                if (value < -1)
                    value = -1;
                if (this.lRAnimationDistance == value)
                    return;

                this.lRAnimationDistance = value;
            }
        }

        private TBMargin tBMargin = new TBMargin(-1, -1);
        /// <summary>
        /// 上下外边距
        /// </summary>
        [Description("上下外边距")]
        [Category("杂项")]
        [PropertyOrder(-186)]
        [DefaultValue(typeof(LRMargin), "-1, -1")]
        public TBMargin TBMargin
        {
            get { return this.tBMargin; }
            set
            {
                if (value.Top < -1)
                    value.Top = -1;
                if (value.Bottom < -1)
                    value.Bottom = -1;
                if (this.tBMargin == value)
                    return;

                this.tBMargin = value;
                this.Invalidate();
            }
        }

        private LRMargin textLRMargin = new LRMargin(-1, -1);
        /// <summary>
        /// 文本左右外边距 （-1采用通用设置）
        /// </summary>
        [Description("文本左右外边距 （-1采用通用设置）")]
        [Category("杂项")]
        [PropertyOrder(-170)]
        [DefaultValue(typeof(LRMargin), "-1, -1")]
        public LRMargin TextLRMargin
        {
            get { return this.textLRMargin; }
            set
            {
                if (value.Left < -1)
                    value.Left = -1;
                if (value.Right < -1)
                    value.Right = -1;
                if (this.textLRMargin == value)
                    return;

                this.textLRMargin = value;
                this.Invalidate();
            }
        }

        private string text = "";
        /// <summary>
        /// 节点文本
        /// </summary>
        [Description("节点文本")]
        [Category("杂项")]
        [PropertyOrder(-168)]
        [DefaultValue("")]
        public string Text
        {
            get { return this.text; }
            set
            {
                if (this.text == value)
                    return;

                this.text = value;
                this.Invalidate();
            }
        }

        private string key = "";
        /// <summary>
        /// 节点标识
        /// </summary>
        [Description("节点标识")]
        [Category("杂项")]
        [PropertyOrder(-167)]
        [DefaultValue("")]
        public string Key
        {
            get { return this.key; }
            set
            {
                value = value.Trim();
                if (this.key == value)
                    return;

                this.key = value;
            }
        }

        private object tag = null;
        /// <summary>
        /// 节点自定义数据
        /// </summary>
        [Description("节点自定义数据")]
        [Category("杂项")]
        [PropertyOrder(-166)]
        [DefaultValue(null)]
        [Bindable(true)]
        [Localizable(false)]
        [TypeConverter(typeof(StringConverter))]
        public object Tag
        {
            get { return this.tag; }
            set { this.tag = value; }
        }

        private bool splitterLineVisible = false;
        /// <summary>
        /// 是否显示分隔线
        /// </summary>
        [Description("是否显示分隔线")]
        [Category("杂项")]
        [PropertyOrder(-138)]
        [DefaultValue(false)]
        public virtual bool SplitterLineVisible
        {
            get { return this.splitterLineVisible; }
            set
            {
                if (this.splitterLineVisible == value)
                    return;

                this.splitterLineVisible = value;
                this.Invalidate();
            }
        }

        private SingleAccordionNodeImageVisibles imageVisible = SingleAccordionNodeImageVisibles.Auto;
        /// <summary>
        /// 是否显示图片（Auto采用通用设置）
        /// </summary>
        [Description("是否显示图片（Auto采用通用设置）")]
        [Category("杂项")]
        [PropertyOrder(-130)]
        [DefaultValue(SingleAccordionNodeImageVisibles.Auto)]
        public SingleAccordionNodeImageVisibles ImageVisible
        {
            get { return this.imageVisible; }
            set
            {
                if (this.imageVisible == value)
                    return;

                this.imageVisible = value;
                this.Invalidate();
            }
        }

        private LRMargin imageLRMargin = new LRMargin(-1, -1);
        /// <summary>
        /// 图片左右外边距
        /// </summary>
        [Description("图片左右外边距")]
        [Category("杂项")]
        [PropertyOrder(-128)]
        [DefaultValue(typeof(LRMargin), "-1, -1")]
        public LRMargin ImageLRMargin
        {
            get { return this.imageLRMargin; }
            set
            {
                if (value.Left < -1)
                    value.Left = -1;
                if (value.Right < -1)
                    value.Right = -1;
                if (this.imageLRMargin == value)
                    return;

                this.imageLRMargin = value;
                this.Invalidate();
            }
        }

        private Size imageSize = new Size(-1, -1);
        /// <summary>
        /// 图片Size
        /// </summary>
        [Description("图片Size")]
        [Category("杂项")]
        [PropertyOrder(-126)]
        [DefaultValue(typeof(Size), "-1, -1")]
        public Size ImageSize
        {
            get { return this.imageSize; }
            set
            {
                if (value.Width < -1)
                    value.Width = -1;
                if (value.Height < -1)
                    value.Height = -1;
                if (this.imageSize == value)
                    return;

                this.imageSize = value;
                this.Invalidate();
            }
        }

        private Image image = null;
        /// <summary>
        /// 图片
        /// </summary>
        [Description("图片")]
        [Category("杂项")]
        [PropertyOrder(-124)]
        [DefaultValue(null)]
        [RefreshProperties(RefreshProperties.Repaint)]
        public virtual Image Image
        {
            get { return this.image; }
            set
            {
                if (this.image == value)
                    return;

                this.image = value;
                this.Invalidate();
            }
        }

        private SingleAccordionNode parent = null;
        /// <summary>
        /// 父节点(SingleAccordionCategoryNode)
        /// </summary>
        [Description("父节点(SingleAccordionCategoryNode)")]
        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public SingleAccordionNode Parent
        {
            get { return this.parent; }
            internal protected set { this.parent = value; }
        }

        private SingleAccordion owner = null;
        /// <summary>
        /// 获取节点所属的控件
        /// </summary>
        [Description("获取节点所属的控件")]
        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public SingleAccordion Owner
        {
            get
            {
                SingleAccordionNode tmp = this;
                while (true)
                {
                    if (tmp.Parent == null)
                    {
                        return tmp.owner;
                    }
                    tmp = tmp.Parent;
                }
            }
            internal protected set { this.owner = value; }
        }

        /// <summary>
        /// 获取节点等级深度（0开始）
        /// </summary>
        [Description("获取节点等级深度（0开始）")]
        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public int Level
        {
            get
            {
                int level = 0;
                SingleAccordionNode tmp = this;
                while (true)
                {
                    if (tmp.Parent == null)
                    {
                        return level;
                    }
                    level += 1;
                    tmp = tmp.Parent;
                }
            }
        }

        /// <summary>
        /// 鼠标是否进入节点
        /// </summary>
        [Description("鼠标是否进入节点")]
        [Browsable(false)]
        public bool IsMouseEnter
        {
            get
            {
                if (this.Owner == null)
                {
                    return false;
                }

                return this.Owner.IsMouseEnter(this);
            }
        }

        private Rectangle rect = Rectangle.Empty;
        /// <summary>
        /// 节点Rect
        /// </summary>
        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public Rectangle Rect
        {
            get { return this.rect; }
            protected internal set { this.rect = value; }
        }

        private SingleAccordionNodeMouseAnimationStatuss mouseAnimationStatus = SingleAccordionNodeMouseAnimationStatuss.MouseLeave;
        /// <summary>
        /// 节点鼠标动画状态
        /// </summary>
        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public SingleAccordionNodeMouseAnimationStatuss MouseAnimationStatus
        {
            get { return this.mouseAnimationStatus; }
            protected internal set { this.mouseAnimationStatus = value; }
        }

        private int mouseAnimationUsedTime = 0;
        /// <summary>
        /// 节点鼠标动画已使用时间
        /// </summary>
        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public int MouseAnimationUsedTime
        {
            get { return this.mouseAnimationUsedTime; }
            protected internal set { this.mouseAnimationUsedTime = value; }
        }

        #endregion

        #region 公开方法

        /// <summary>
        /// 刷新控件
        /// </summary>
        internal protected virtual void Invalidate()
        {
            if (this.owner != null)
            {
                this.owner.Invalidate();
            }
        }

        /// <summary>
        /// 重新计算控件并刷新控件
        /// </summary>
        internal protected virtual void InitializeInvalidate()
        {
            if (this.owner != null)
            {
                this.owner.UpdateRealityRectangle();
                this.owner.UpdateAllNodeRectangle();
                this.owner.UpdateScrollRectangle();
                this.owner.Invalidate();
            }
        }

        /// <summary>
        /// 复制节点
        /// </summary>
        /// <param name="copyChildrens">是否复制子节点</param>
        /// <returns></returns>
        public virtual SingleAccordionNode Copy(bool copyChildrens = false)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// 获取节点鼠标动画启用状态
        /// </summary>
        /// <returns></returns>
        public virtual bool GetMouseAnimationEnabled()
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// 获取节点鼠标动画总时间
        /// </summary>
        /// <returns></returns>
        public virtual int GetMouseAnimationAllTime()
        {
            throw new NotImplementedException();
        }

        #endregion

    }

}
